Skip to content

Add Compression best practices guide#52968

Draft
alinpahontu2912 wants to merge 3 commits intodotnet:mainfrom
alinpahontu2912:zip_tar_bestpractices
Draft

Add Compression best practices guide#52968
alinpahontu2912 wants to merge 3 commits intodotnet:mainfrom
alinpahontu2912:zip_tar_bestpractices

Conversation

@alinpahontu2912
Copy link
Copy Markdown
Member

@alinpahontu2912 alinpahontu2912 commented Apr 10, 2026

Summary

Add a guide explaining how to best work with Zip and Tar archives in .NET.


Internal previews

📄 File 🔗 Preview link
docs/fundamentals/toc.yml docs/fundamentals/toc
docs/standard/io/zip-tar-best-practices.md Best practices for working with ZIP and TAR archives in .NET

Comment thread docs/standard/io/zip-tar-best-practices.md
Comment thread docs/standard/io/zip-tar-best-practices.md Outdated
Comment thread docs/standard/io/snippets/zip-tar-best-practices/csharp/Program.cs Outdated
Comment thread docs/standard/io/snippets/zip-tar-best-practices/csharp/Program.cs Outdated
Comment thread docs/standard/io/snippets/zip-tar-best-practices/csharp/Program.cs Outdated
Comment thread docs/standard/io/zip-tar-best-practices.md Outdated
Comment thread docs/standard/io/zip-tar-best-practices.md Outdated
Comment thread docs/standard/io/zip-tar-best-practices.md Outdated
Comment thread docs/standard/io/zip-tar-best-practices.md Outdated
Comment thread docs/standard/io/zip-tar-best-practices.md Outdated
Copy link
Copy Markdown
Member

@rzikm rzikm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's getting better, few additional comments.

continue;

// Normalize and validate the path, same as the ZIP example.
string destPath = Path.GetFullPath(Path.Join(fullDestDir, entry.Name));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some samples use Path.Join, some Path.Combine, is there a meaningful difference between the two?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Path.Combine returns just the second argument when it's a rooted path (starts with /), so Path.Combine("/dest", "/etc/passwd") gives /etc/passwd.
Path.Join always concatenates both. I will update safe samples to use Path.Join. difference here

Comment thread docs/standard/io/snippets/zip-tar-best-practices/csharp/Program.cs Outdated
Comment on lines +243 to +257
void TarStreamingRead(Stream archiveStream)
{
using var reader = new TarReader(archiveStream);
TarEntry? entry;
while ((entry = reader.GetNextEntry()) is not null)
{
if (entry.DataStream is not null)
{
string safePath = "output.bin";
// Copy now — the stream becomes invalid after the next GetNextEntry() call
using var fileStream = File.Create(safePath);
entry.DataStream.CopyTo(fileStream);
}
}
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure what this code snippet is supposed to illustrate

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should show that the datastream must be consumed before the next getentry call. I'll redo it to make it clearer

Comment thread docs/standard/io/zip-tar-best-practices.md
Comment thread docs/standard/io/zip-tar-best-practices.md Outdated
Comment thread docs/standard/io/zip-tar-best-practices.md Outdated
Comment thread docs/standard/io/zip-tar-best-practices.md Outdated
Comment thread docs/standard/io/zip-tar-best-practices.md Outdated

## Data integrity

ZIP entries include a CRC-32 checksum that you can use to verify data hasn't been corrupted or tampered with.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should also mention TAR CRC in the first paragraph, now users might assume that this section is Zip-only and skip the rest of it.

@alinpahontu2912 alinpahontu2912 requested a review from rzikm April 16, 2026 13:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants